package Easy汉明距离;

import org.testng.annotations.Test;

public class Solution {
    public int hammingDistance(int x, int y) {
        int z = x^y;
        int sum = 0;
        while (z != 0) {
            z = z & (z - 1);
            sum++;
        }
//        while(num!=0){
//            if (num%2!=0)
//                sum++;
//            num = num/2;
//        }
        return sum;
    }
    public int hammingDistance1(int x, int y) {
        return Integer.bitCount(x ^ y);
    }
    @Test
    public void test(){
        System.out.println(hammingDistance(1,4));
    }
}
